﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using WindowsFormsApplication3;

namespace bsy
{
    public partial class SeriesAdd : Form
    {
        public SeriesAdd()
        {
            InitializeComponent();
        }

        private void SeriesAdd_button1_Click(object sender, EventArgs e)
        {
            String seriesName = SeriesAdd_textBox1.Text.Trim();
            if (seriesName == "")
            {
                MessageBox.Show("不能添加空系列名称！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                try
                {
                    //检索数据库中是否存在重复的系列名称
                    String sql = "select PS_name from productsort where P_id is null";
                    DataSet ds = new DataSet();
                    ds = CommonDB.Query(sql);
                    int count = ds.Tables[0].Rows.Count;//获取存入DataSet中Table的长度
                    for (int i = 0; i < count; i++)
                    {
                        String PS_name = (String)ds.Tables[0].Rows[i][0];
                        if (seriesName == PS_name)
                        {
                            MessageBox.Show("'" + seriesName + "'" + "已存在！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    String sql1 = "insert into productsort(PS_name) values('" + seriesName + "')";
                    int temp = CommonDB.ExecuteSql(sql1);
                    if (temp == 1)
                    {
                        MessageBox.Show("添加成功！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.DialogResult = DialogResult.OK;

                    }
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("错误提示：" + sqle.Message);
                }
            }
        }
      private void SeriesAdd_button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
